#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/1/13 17:34
# @Author  : Zangzihan
# @File    : contrast_file_name.py
# @Description : 这个是用来找出文件夹下所有的xml文件，并挑选出对应的jpg图片，放到一个文件夹内


import os
import shutil

import glob

input_path = r"F:\0shougang\ir\Images_d_d"
output_path = r"F:\0shougang\ir\Images_d_d_d"

# 查找该目录及其子目录下所有的xml文件
xml_files = glob.glob(input_path + '**/*.json', recursive=True)
for xml_file in xml_files:
    # xml文件名
    xml_name = os.path.basename(xml_file)
    # xml文件名前缀
    xml_prefix = os.path.splitext(xml_name)[0]
    print("xml_prefix:", xml_prefix)
    # xml文件名后缀
    xml_suffix = os.path.splitext(xml_name)[1]
    target_img_name = os.path.join(input_path, xml_prefix+".png")
    print(target_img_name)
    target_json_name = os.path.join(input_path, xml_name)
    if os.path.exists(target_img_name):
        print("target_file_name:", target_img_name)
        shutil.copy2(target_img_name, output_path)
        shutil.copy2(target_json_name, output_path)
